package com.yuwei.mine.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.yuwei.base.RoutePath
import com.yuwei.mine.R
import com.yuwei.mine.databinding.LayoutSettingItemBinding
import com.yuwei.mine.entity.SettingEntity

class SettingAdapter(val data:List<SettingEntity>):RecyclerView.Adapter<SettingAdapter.SettingViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SettingViewHolder {
         val itemDataBinding=LayoutSettingItemBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return SettingViewHolder(itemDataBinding)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    override fun onBindViewHolder(holder: SettingViewHolder, position: Int) {
        val itemData=data[position]
        val img = holder.itemView.findViewById<ImageView>(R.id.iv_icon)
        Glide.with(holder.itemView.context).load(itemData.img).into(img)
        holder.itemView.findViewById<TextView>(R.id.tv_title).setText(itemData.title)
        holder.itemView.setOnClickListener {
            when(position){
                0->{
                    ARouter.getInstance().build(RoutePath.MODULE_MINE_ORDERS_ACTIVITY).navigation()
                }
                4->{
                    ARouter.getInstance().build(RoutePath.MODULE_MINE_MY_STORE_ACTIVITY).navigation()
                }
            }
        }
    }

    class SettingViewHolder(val itemDataBinding:LayoutSettingItemBinding):RecyclerView.ViewHolder(itemDataBinding.root)

}